import 'package:flutter/material.dart';

///
/// 单选框-含标题
///
class QRadioBox extends StatelessWidget {
  final double? fontSize;
  final double width;
  final String? icon;
  final String title;
  final int index;
  final int selectIndex;
  final Function(int i)? tapCallback;

  const QRadioBox({
    Key? key,
    required this.width,
    required this.index,
    required this.selectIndex,
    this.fontSize,
    this.icon,
    this.title = "",
    this.tapCallback,
  }) : super(key: key);

  @override
  Widget build(BuildContext context) {
    bool isSure = index == selectIndex;

    return GestureDetector(
      onTap: () {
        if (tapCallback != null) {
          tapCallback!(index);
        }
      },
      child: Row(
        mainAxisAlignment: MainAxisAlignment.start,
        children: [
          Container(
            width: width,
            height: width,
            decoration: BoxDecoration(
              border: Border.all(
                  width: 1,
                  color: isSure
                      ? const Color(0xFF177FF3)
                      : const Color.fromRGBO(151, 151, 151, 1)),
              borderRadius: BorderRadius.circular(30),
              color: isSure ? const Color(0xFF177FF3) : Colors.transparent,
            ),
            child: Offstage(
              offstage: isSure ? false : true,
              child: icon == null
                  ? const Icon(
                      Icons.check,
                      size: 10,
                      color: Colors.white,
                    )
                  : Image.asset(
                      icon!,
                      color: Colors.white,
                      width: width,
                      height: width,
                    ),
            ),
          ),
          Container(
            padding: const EdgeInsets.only(left: 5),
            child: Text(
              title,
              style: TextStyle(
                fontSize: fontSize ?? 14,
                color: const Color.fromRGBO(96, 105, 114, 1),
              ),
            ),
          )
        ],
      ),
    );
  }
}
